/**
 * @file
 * @author dousha
 * @date 2020/11/30.
 */

#include "linear_feedback_shift_register.h"

static uint32_t lfsr = 0;

void lfsr_init(uint32_t seed) {
	lfsr = seed;
}

uint8_t lfsr_step() {
	uint8_t out = lfsr & 1u;
	uint32_t feed;
	feed = (lfsr & (1u << 29u)) ^ (lfsr & (1u << 25u)) ^ (lfsr & (1u << 24u));
	lfsr >>= 1u;
	lfsr |= feed ? 0x80000000u : 0u;
	return out;
}

uint8_t lfsr_get_byte() {
	return (lfsr >> 16u) & 0xffu;
}
